home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / scrasm / gensq.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-09  |  3.2 KB  |  102 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <memory.h>
  4. #include <stdlib.h>
  5.  
  6. #define WIDTH   256
  7.  
  8. #define FILENAME "DIAGONAL.TIL"
  9. char    fn[100] = FILENAME;
  10. typedef unsigned char BYTE;
  11. typedef BYTE    ROW[16];
  12. typedef ROW     BITMAP[16];
  13.  
  14. BITMAP  b;
  15. BITMAP  c;
  16.  
  17. BITMAP  pattern={{1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0},
  18.                  {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  19.                  {1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0},
  20.                  {1,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0},
  21.                  {1,0,0,1,0,0,0,0,0,0,0,2,0,0,0,0},
  22.                  {0,0,1,0,0,1,1,0,1,1,0,0,2,0,0,0},
  23.                  {0,0,1,0,0,1,2,0,1,2,0,0,2,0,0,0},
  24.                  {0,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0},
  25.                  {0,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0},
  26.                  {0,1,0,0,1,2,0,0,0,1,2,0,0,2,0,0},
  27.                  {0,0,1,0,1,2,1,1,1,1,2,0,2,0,0,0},
  28.                  {0,0,1,0,0,2,2,2,2,2,0,0,2,0,0,2},
  29.                  {0,0,0,1,0,0,0,0,0,0,0,2,0,0,0,2},
  30.                  {0,0,0,0,2,2,0,0,0,2,2,0,0,0,0,2},
  31.                  {0,0,0,0,0,0,2,2,2,0,0,0,0,0,2,2},
  32.                  {0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2}};
  33.  
  34. void copy_pattern(BITMAP b,BITMAP patt, BYTE l, BYTE m, BYTE h)
  35.         {
  36.         int     x,y;
  37.  
  38.         for (y=0; y<16; y++) {
  39.                 for (x=0; x<16; x++) {
  40.                         switch (patt[y][x]) {
  41.                                 case 0:
  42.                                         b[y][x] = m;
  43.                                         break;
  44.                                 case 1:
  45.                                         b[y][x] = l;
  46.                                         break;
  47.                                 case 2:
  48.                                         b[y][x] = h;
  49.                                         break;
  50.                                 }
  51.                         }
  52.                 }
  53.         }
  54.  
  55. /* Transforms linear to planar */
  56. void transform(BITMAP b,BITMAP c)
  57.         {
  58.         int     x,y,p;
  59.         BYTE    *pb = (BYTE *)c;
  60.  
  61.         for (p=0; p<4; p++) {
  62.                 for (y=0; y<16; y++) {
  63.                         for (x=0; x<16; x+=4) {
  64.                                 *(pb++) = b[y][x+p];
  65.                                 }
  66.                         }
  67.                 }
  68.         }
  69.  
  70. void main(int argc,char *argv[])
  71.         {
  72.         FILE    *fp;
  73.         int     i;
  74.         int     width = WIDTH;
  75.  
  76.         fp = fopen(fn,"wb");
  77.         if (!fp) {
  78.                 printf("Couldn't open %s for write.\n",fn);
  79.                 exit(1);
  80.                 }
  81.         if (argc > 1) {
  82.                 width = atoi(argv[1]);
  83.                 if (width > WIDTH)
  84.                         width = WIDTH;
  85.                 printf("Width = %d\n",width);
  86.                 }
  87.  
  88.         for (i = 0; i< width; i++) {
  89.                 BYTE    less,more;
  90.  
  91.                 less = (BYTE)((i + width - 1) % width);
  92.                 more = (BYTE)((i + 1) % width);
  93.                 copy_pattern(b, pattern, less, (BYTE)i, more);
  94.                 transform(b,c);
  95.                 fwrite(c, 16,16, fp);
  96.                 printf("Square %d\r",i);
  97.                 }
  98.         fclose(fp);
  99.         printf("All done!     \n");
  100.         exit(0);
  101.         }
  102.